package com.xszx.knowledge.job;

import com.xszx.knowledge.interceptor.LoginInterceptor;
import com.xszx.knowledge.service.EbookService;
import com.xszx.knowledge.service.EbookSnapshotService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;

/**
 * 从电子书表中定时生成中间表的数据
 */
@Configuration
@EnableScheduling   //开启定时任务
public class ScheduleSnapshotTask {
    @Resource
    private EbookSnapshotService ebookSnapshotService;
    private static final Logger LOG = LoggerFactory.getLogger(LoginInterceptor.class);
    @Scheduled(cron = "0 0/1 * * * ?")
    public void updateEbook() {
        LOG.info("生成中间表电子书信息开始");
        long startTime = System.currentTimeMillis();
        //执行更新操作
        ebookSnapshotService.initStatistic();
        LOG.info("-------------定时任务结束 耗时：{} ms -------------", System.currentTimeMillis() - startTime);
    }
}
